package vo;

import java.util.List;

import factory.DAOFactory;

/**
 * 广告信息类
 * 
 */
public class Advertise {
	private int ad_id;
	private String title;
	private Person user;
	/**
	 * @return the user
	 */
	public Person getUser() {
		return user;
	}
	/**
	 * @param user the user to set
	 */
	public void setUser(Person user) {
		this.user = user;
	}
	private String content;
	private String time;
	private int sender;
	private StringBuffer showAdList;
	private StringBuffer showAdList1;
	private StringBuffer showAdList2;
	/**
	 * @return the ad_id
	 */
	public int getAd_id() {
		return ad_id;
	}
	/**
	 * @param ad_id the ad_id to set
	 */
	public void setAd_id(int ad_id) {
		this.ad_id = ad_id;
	}
	/**
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}
	/**
	 * @param title the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}
	/**
	 * @return the content
	 */
	public String getContent() {
		return content;
	}
	/**
	 * @param content the content to set
	 */
	public void setContent(String content) {
		this.content = content;
	}
	/**
	 * @return the time
	 */
	public String getTime() {
		return time;
	}
	/**
	 * @param time the time to set
	 */
	public void setTime(String time) {
		this.time = time;
	}
	/**
	 * @return the sender
	 */
	public int getSender() {
		return sender;
	}
	/**
	 * @param sender the sender to set
	 */
	public void setSender(int sender) {
		this.sender = sender;
	}
	/**
	 * 展示广告
	 * @return
	 */
	public StringBuffer getShowAdList() {
		List<Advertise> list = DAOFactory.getAdDAOInstance().showAllList(user.getUser_id());
		showAdList = new StringBuffer();
		for (Advertise advertise : list) {
			showAdList.append("<div class=\"news-wrapper single-news mb-55\">");
			showAdList.append("<div class=\"news-text\">");
			showAdList.append("<span>发布时间" + advertise.getTime() +"</span>");
			showAdList.append("<h3><a href=\"blog-details.html\">"+ advertise.getTitle() + "</a></h3>");
			showAdList.append("<p>"+ advertise.getContent() +"</p>");
			showAdList.append("<a type=\"button\" class=\"btn btn-success\" href=\"SearchAdById?id=" + advertise.getAd_id() + "\">编辑</a>");
			showAdList.append("<a type=\"button\" class=\"btn btn-warning\" href=\"DeleteAdServlet?id="+ advertise.getAd_id()+"\">删除</a>");
			showAdList.append("</div>");
			showAdList.append("</div>");
		}
		return showAdList;
	}
	public StringBuffer getShowAdList1() {
		List<Advertise> list = DAOFactory.getAdDAOInstance().showAllAd();
		showAdList = new StringBuffer();
		for (Advertise advertise : list) {
			showAdList.append("<div class=\"news-wrapper single-news mb-55\">");
			showAdList.append("<div class=\"news-text\">");
			showAdList.append("<span>发布时间" + advertise.getTime() +"</span>");
			showAdList.append("<h3><a href=\"blog-details.html\">"+ advertise.getTitle() + "</a></h3>");
			showAdList.append("<p>"+ advertise.getContent() +"</p>");
			showAdList.append("</div>");
			showAdList.append("</div>");
		}
		return showAdList;
	}
	public StringBuffer getShowAdList2() {
		List<Advertise> list = DAOFactory.getAdDAOInstance().searchByTitle(title);
		showAdList = new StringBuffer();
		for (Advertise advertise : list) {
			showAdList.append("<div class=\"news-wrapper single-news mb-55\">");
			showAdList.append("<div class=\"news-text\">");
			showAdList.append("<span>发布时间" + advertise.getTime() +"</span>");
			showAdList.append("<h3><a href=\"blog-details.html\">"+ advertise.getTitle() + "</a></h3>");
			showAdList.append("<p>"+ advertise.getContent() +"</p>");
			showAdList.append("</div>");
			showAdList.append("</div>");
		}
		return showAdList2;
	}
}
